<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
require_once JPATH_BASE .DS. 'components' .DS. 'com_mariageplanner' .DS. 'helpers' .DS. 'modeladmin.php';

/**
 * Layout Model
 */
class MariagePlannerModelLayout extends MariagePlannerBaseModelAdmin
{	
	protected $_table_name = 'layout';

	public function getTable($type = 'Layout', $prefix = 'MariagePlannerTable', $config = array())
	{
		return JTable::getInstance($type, $prefix, $config);
	}
	
	public function getForm($data = array(), $loadData = true)
	{
		// Get the form.
		$form = $this->loadForm('com_mariageplanner.layout', 'layout', array('control' => 'jform', 'load_data' => $loadData));
		if (empty($form)) {
			return false;
		}
	
		return $form;
	}
	
	public function saveLayout()
	{	
		if(!$this->_canEdit(null)) {
			return false;
		} else {
			$id = $this->getState('item.id');		
			$layout = JRequest::getString('layout_scheme', 0, 'post');

			if(empty($id))
				return false;
			
			$tbl = $this->getTable();
			$tbl->load($id);
			
			if(empty($tbl->id))
				return false;
			
			$tbl->layout = $layout;
			$tbl->store();
			
			return true;
		}
	}	
	
	public function getGuests()
	{
		$db			= $this->getDbo();
		$query		= $db->getQuery(true);
	
		$query->select('*');
		$query->from('#__mariageplanner_guests');
		$query->order('`name` ASC');
		$query->where('planner_id=' . (int)$this->getState('planner.id', 0));
	
		$db->setQuery($query);
		$data = $db->loadObjectList();
	
		if (!$db->query()) {
			JError::raiseError(500, $db->getErrorMsg());
		}
	
		return $data;
	}

}
?>